package com.hot100.easy;

/**
 * @ClassName Demo08
 * @Description 求树的最大深度
 * @Author zt
 * @Date 16:50 2022/6/9
 * @Version 1.0
 **/
public class Demo08 {

    public int maxDepth(TreeNode root) {
           if(root==null){
               return 0;
           }
           return Math.max(maxDepth(root.left),maxDepth(root.right))+1;
    }


    /**
     * Definition for a binary tree node.
     *
     */
    public class TreeNode {
        int val;
        TreeNode left;
        TreeNode right;
        TreeNode() {}
        TreeNode(int val) { this.val = val; }
        TreeNode(int val, TreeNode left, TreeNode right) {
            this.val = val;
            this.left = left;
            this.right = right;
        }
    }
}